import { getBusinessList } from '@/services/common';
import { customTrimFunc } from '@/utils/utils.jsx';

//表单配置项
const formItemData = {
  'merchantNos': {
    itemConfig: {
      name: 'merchantNos'
    },
    elConfig: {
      mode: "multiple",
      maxTagCount: 1,
      formType: 'SearchSelect',
      placeholder: '门店名称',
      needFetchFirst: false,
      fetchOptions: handleRefundUserList,
      style: {
        width: '320px'
      }
    }
  },
}

//获取操作人列表
function handleRefundUserList(storeName) {
  return new Promise(async (resolve, reject) => {
    const { data, success } = await getBusinessList(customTrimFunc({ 
      storeName: storeName,
      current: 1,
      size: 50
    }));
    if (success) {
      const newArr = [];
      data.filter(v => v.merchantNo).map(item => {
        newArr.push({
          label: item.storeName,
          value: item.merchantNo,
        })
      })
      resolve(newArr);
    } else {
      reject();
    }
  })
}

//处理表单数据
export const getFormItem = (optionsData, type) => {
  const arr = [];
  Object.keys(formItemData).map(v => {
    if(!['0', '1', '2'].includes(type) && v == 'warehouseId') {
      return;
    }
    if(type != '3' && v == 'printType') {
      return;
    }
    if(optionsData && optionsData[v]) {
      formItemData[v].elConfig.options = optionsData[v];
    }
    arr.push(formItemData[v]);
  })
  return arr;
}
